package com.aijk.ehm.service;

import com.aijk.base.entity.PagingRequest;
import com.aijk.commons.utils.Utils;
import com.aijk.ehm.dao.mybatis.SysAppVersionMapper;
import com.aijk.ehm.model.SysAppVersion;
import com.aijk.ehm.model.SysAppVersionExample;
import com.aijk.ehm.model.qo.SysAppVersionQo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysAppVersionService {
    private static Logger logger = LoggerFactory.getLogger(SysAppVersionService.class);

    @Autowired
    private SysAppVersionMapper mapper;

    public SysAppVersionExample getExample(SysAppVersionQo qo) {
        SysAppVersionExample example = new SysAppVersionExample();
        SysAppVersionExample.Criteria criteria = example.createCriteria();
        if (qo != null) {
            if (Utils.isNotEmpty(qo.getSortway())) example.setOrderByClause(qo.getSortway());
            if (qo.getAppname()!=null && !qo.getAppname().equals("")) criteria.andAppnameLike("%" + qo.getAppname() + "%");
            if (qo.getAppcode()!=null) criteria.andAppcodeEqualTo(qo.getAppcode());
            if (qo.getVersion()!=null) criteria.andVersionGreaterThan(qo.getVersion());
            if (qo.getOsType()!=null) criteria.andOsTypeEqualTo(qo.getOsType());
            if (qo.getIsForce()!=null) criteria.andIsForceEqualTo(qo.getIsForce());

        }
        return example;
    }

    public int count(SysAppVersionQo qo) {
        return mapper.countByExample(getExample(qo));
    }

    public int save(SysAppVersion bean) {
        return mapper.insertSelective(bean);
    }

    public int delete(Long id) {
        return mapper.deleteByPrimaryKey(id);
    }

    public int update(SysAppVersion bean) {
        return mapper.updateByPrimaryKeySelective(bean);
    }

    public SysAppVersion findOne(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    public List<SysAppVersion> find(SysAppVersionQo qo) {
        return mapper.selectByExample(getExample(qo));
    }

    public PageInfo<SysAppVersion> page(PagingRequest pagingRequest, SysAppVersionQo qo) {
        PageHelper.startPage(pagingRequest.getPageNum() , pagingRequest.getPageSize());
        return new PageInfo<SysAppVersion>(mapper.selectByExample(getExample(qo)));
    }
}